package ldh.im.fxbase.data.pojo.status;

import ldh.rpc.dto.ValueEnum;
import ldh.im.dto.enums.MessageFileStatus;

public enum ImMessageFileStatus implements ValueEnum<Byte> {
    // 发送端状态
    none(0, "空"),              // 服务端已经上传成功
    created(1, "已创建"),       // 已经创建
    uploading(2, "上传中"),     // 上传中
    uploaded(3, "已上传"),      // 发送到服务器，并返回成功
    downloaded(4, "已下载"),    // 已下载
    downloading(5, "下载中"),   // 正在上传中
    ;

    private Byte value;
    private String desc;

    private ImMessageFileStatus(Integer value, String desc){
        this.value = value.byteValue();
        this.desc = desc;
    }

    @Override
    public Byte getValue() {
        return value;
    }

    public String getDesc() {
        return desc;
    }

    public static ImMessageFileStatus wrap(MessageFileStatus fileStatus, boolean isSender) {
        if (fileStatus == MessageFileStatus.none) {
            return none;
        } else if (fileStatus == MessageFileStatus.uploaded) {
            return isSender ? downloaded : uploaded;
        } else if (fileStatus == MessageFileStatus.downloading) {
            return isSender ? downloaded : uploaded;
        } else if (fileStatus == MessageFileStatus.downloaded) {
            return isSender ? downloaded : uploaded;
        }
        throw new RuntimeException("ImMessageFileStatus不支持这种类型MessageFileStatus(" + fileStatus.name() + ")");
    }

    public static ImMessageFileStatus getByValue(Integer value) {
        if (value == null) return null;
        for (ImMessageFileStatus messageStatus : ImMessageFileStatus.values()) {
            if (messageStatus.getValue() == value.byteValue()) {
                return messageStatus;
            }
        }

        throw new RuntimeException("ImMessageFileStatus不支持这个值：" + value);
    }
}
